﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.Stock
{
    public class StockPresenter : Presenter<IStockView>
    {
        public StockPresenter(IStockView view)
            : base(view)
        {
        }

        public void Display(string stockId)
        {
            if (stockId == null) return;

            var stock = Model.GetStock(stockId);

            View.StockID = stock.StockID;
            View.StockCode = stock.StockCode;
            View.StockName = stock.StockName;
            View.Description = stock.Description;
            View.RestaurantID = stock.RestaurantID;
            View.IsActive = stock.IsActive;
        }

        public int Save()
        {
            var stock = new StockModel
            {
                StockID = View.StockID,
                StockCode = View.StockCode,
                StockName = View.StockName,
                RestaurantID = View.RestaurantID,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.StockID == null)
                return Model.AddStock(stock);
            else
                return Model.UpdateStock(stock);
        }

        public int Delete(string stokcId)
        {
            return Model.DeleteStock(stokcId);
        }
    }
}
